package com.aaa.hospital.nurse.controller;

import com.aaa.hospital.ManagementEnd.pojo.Diagnose;
import com.aaa.hospital.ManagementEnd.service.DiagnoseService;
import com.aaa.hospital.ManagementEnd.service.RegistrationServices;
import com.aaa.hospital.nurse.pojo.Ward_occupancy_information;
import com.aaa.hospital.nurse.pojo.Wardregistration;
import com.aaa.hospital.nurse.service.BedsService;
import com.aaa.hospital.nurse.service.WardregistrationDaoService;
import com.aaa.hospital.nurse.service.WardregistrationService;
import com.aaa.hospital.nurse.util.TheWardDB;
import com.aaa.hospital.nurse.util.WardrehistrationDB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class WardregistrationController {
    @Autowired
    private WardregistrationService wardregistrationService;

    @Autowired
    private WardregistrationDaoService wardregistrationDaoService;

    @Autowired
    private BedsService bedsService;

    @Autowired
    private DiagnoseService diagnoseService;
    //预约
    @Autowired
    private RegistrationServices registrationServices;
    @RequestMapping("warqueryById")
    @ResponseBody
    public List<WardrehistrationDB> warqueryById(int visid){
        List<WardrehistrationDB> list=wardregistrationService.queryById(visid);


        return list;
    }

    @RequestMapping("/thewarqueryByName")
    @ResponseBody
    public String thewarqueryByName(Integer id){
        List<Wardregistration> list=wardregistrationDaoService.queryById(id);
        if(list.size()>0){
            return "1";

        }else{
            return "0";
        }

    }



    @RequestMapping("/openthewardcommit")
    @ResponseBody
    public String openthewardcommit(TheWardDB theWardDB,Integer bedid,Integer uid){
        theWardDB.setBedid(bedid);
        theWardDB.setUid(uid);
        List<Wardregistration> list= wardregistrationService.queryByName(uid);
        Ward_occupancy_information list2=new Ward_occupancy_information();
        list2.setWarid(list.get(0).getWarid());
        list2.setBedid(theWardDB.getBedid());
        list2.setNurid(3002);
        list2.setBfid(theWardDB.getBfid());
        wardregistrationService.insert(list2);
        wardregistrationDaoService.update(list.get(0).getWarid());
        bedsService.update1(theWardDB.getBfid(), theWardDB.getBedid());
        return "1";
    }


    //11/9
    //lgq
    //住院辦理

    @RequestMapping("/wardregist/wardinsert")
    @ResponseBody
    public boolean wardinsert(Integer diid,Integer bfqyid,String note,Integer yydid,Integer ydbh, Integer  visid,Integer tjid,String bqms,String grs,String jzs,String yszd,String yz){
        Wardregistration wardr = new Wardregistration();
        wardr.setVisid(visid);
        wardr.setDid(diid);
        wardr.setBfqyid(bfqyid);
        wardr.setNotes(note);
        boolean wardregistinsert = wardregistrationDaoService.wardregistinsert(wardr);
        if (wardregistinsert == true) {
     Diagnose diagnose=new Diagnose(null,ydbh,visid,diid,tjid,null,bqms,yszd,jzs,grs,yz,1,null);
            boolean insert = diagnoseService.insert(diagnose);
            if (insert == true) {
                registrationServices.update_state(yydid,2);
                   return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }







}
